package utils;

import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;

/**
 *属性动画工具类
 * Created by lt on 2018\1\6 0006.
 */

public class AnimationProUtils {
    /**
     * 缩小至Gone
     * @param view
     */
    public static void scaleToGoneAnim(View view,int duration){
        view.animate().scaleX(0.0f).scaleY(0.0f).setInterpolator(new LinearInterpolator()).setDuration(duration).start();
    }
    /**
     * 放大至Visible
     * @param view
     */
    public static void scaleToVisibleAnim(View view,int duration){
        view.animate().scaleX(1.0f).scaleY(1.0f).setInterpolator(new LinearInterpolator()).setDuration(duration).start();
    }

    /**
     * 把view的高缩小为原来的一半
     * @param view
     */
    public  static void scaleYToHalf(View view){
        view.animate().scaleY(0.5f).setInterpolator(new LinearInterpolator()).setDuration(500).start();
        view.animate().scaleX(0.7f).setInterpolator(new LinearInterpolator()).setDuration(500).start();
    }
    /**
     * 把view的高缩小为原来的一半
     * @param view
     */
    public  static void scaleYToOrigin(View view){
        view.animate().scaleY(1.0f).setInterpolator(new LinearInterpolator()).setDuration(500).start();
        view.animate().scaleX(1.0f).setInterpolator(new LinearInterpolator()).setDuration(500).start();
    }

    /**
     * 把view 向上平移view的高的一半
     */
    public  static void  translateYUp(View view1,View view2,int dis){
        view1.animate().translationY(-dis).setInterpolator(new LinearInterpolator()).setDuration(500).start();
        view2.animate().translationY(-dis*2).setInterpolator(new LinearInterpolator()).setDuration(500).start();
    }
    /**
     * 把view 向下平移view的高的一半
     */
    public  static void  translateYDown(View view1,View view2,int dis){
        view1.animate().translationY(dis).setInterpolator(new LinearInterpolator()).setDuration(500).start();
        view2.animate().translationY(dis).setInterpolator(new LinearInterpolator()).setDuration(500).start();
    }

    public static  void alpha0To1(View view,int duration){
        ObjectAnimator animator=ObjectAnimator.ofFloat(view,"Alpha",0f,1f);
        animator.setInterpolator(new LinearInterpolator());
        animator.setDuration(duration);
        animator.start();
    }
    public static  void alpha1To0(View view,int duration){
        ObjectAnimator animator=ObjectAnimator.ofFloat(view,"Alpha",1f,0f);
        animator.setInterpolator(new LinearInterpolator());
        animator.setDuration(duration);
        animator.start();
    }


}
